#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2019/10/21  20:17
# @Author: 余浪人
# @email: yulangren520@gmail.com
import json
from datetime import datetime
from apps.control import sys_bp
from pyecharts.charts import Bar
from apps.lib.public import getEveryDay, redis_
from pyecharts import options as opts
from flask_login import login_required
from flask import render_template
from apps.models.order_model import TL_PayOrder_Model
@sys_bp.route ('/records_center',endpoint ='records_center',methods =['GET'])
@login_required
def records_center ():
    return render_template ('system_template/chart.html')
@sys_bp .route ('/order_pay_chart',endpoint ='order_pay_chart',methods =['GET'])
@login_required
def order_pay_chart ():
    OOOOOO000OO0000OO =getEveryDay ()
    O00O0O0OOO00000OO ,OO0OO0OOOO0O0O0OO =datetime .strptime (OOOOOO000OO0000OO [0 ],"%Y-%m-%d"),datetime .strftime (datetime .now (),"%Y-%m-%d %H:%M:%S")
    O000OO00OOOO0O0O0 =TL_PayOrder_Model .query .filter (TL_PayOrder_Model .send_pay_date >=O00O0O0OOO00000OO ,TL_PayOrder_Model .send_pay_date <=OO0OO0OOOO0O0O0OO ).all ()
    O0O0OO000OO0O000O =[float (O00O0O00O0O000O00 .total_amount )for O00O0O00O0O000O00 in O000OO00OOOO0O0O0 ]
    O0OO0OOO00O00OOOO ={_O000OOOO0O00OO000 :0 for _O000OOOO0O00OO000 in OOOOOO000OO0000OO }
    for O00OO0O00OO0OOOOO in O000OO00OOOO0O0O0 :
        OO0OOOO0OO00O0OO0 =datetime .strftime (O00OO0O00OO0OOOOO .send_pay_date ,"%Y-%m-%d")
        O0OO0OOO00O00OOOO [OO0OOOO0OO00O0OO0 ]=sum ([float (O0OO0OOO00O00OOOO [OO0OOOO0OO00O0OO0 ]),float (O00OO0O00OO0OOOOO .total_amount )])
    OOOOOOO00O00OO0OO =(Bar ().add_xaxis ([OO00O0O0O00000O00 for OO00O0O0O00000O00 in OOOOOO000OO0000OO ]).add_yaxis ("支付宝收益",[OOO00O0OOO000OO00 for _OOO0OOO000OO0OO00 ,OOO00O0OOO000OO00 in O0OO0OOO00O00OOOO .items ()],category_gap ="80%").add_yaxis ("微信收益",[0 for _OO0O00000OOO0000O in range (30 )],is_selected =False ,).set_global_opts (title_opts =opts .TitleOpts (title ="收益(月)",subtitle =f"月总收益: ( %.2f )/元"%sum (O0O0OO000OO0O000O ))))
    return OOOOOOO00O00OO0OO .dump_options_with_quotes ()
@sys_bp .route ('/visit_user_chart',endpoint ='visit_user_chart',methods =['GET'])
@login_required
def visit_user ():
    OOOOOO0OOOOOO0000 =getEveryDay ()
    OOO0O000OOOOO00OO =[]
    OOOOOO0000O00O0O0 =redis_ (db =5 )
    for OO00O0OOOO0OOOO0O in OOOOOO0OOOOOO0000 :
        OO000O0OO000OO00O =OOOOOO0000O00O0O0 .hget ('tl_visit_num',OO00O0OOOO0OOOO0O )
        if OO000O0OO000OO00O :OOO0O000OOOOO00OO .append (json .loads (OO000O0OO000OO00O ))
    OOOOO000O0000OOO0 =(Bar ().add_xaxis ([OOOO00OOOO0O0OO00 for OOOO00OOOO0O0OO00 in OOOOOO0OOOOOO0000 ]).add_yaxis ("用户访问量",[OOOOOO0000O00O0O0 .hget ('tl_visit_num',O0O00000OOOOOO0OO )for O0O00000OOOOOO0OO in OOOOOO0OOOOOO0000 ],category_gap ="90%").set_global_opts (title_opts =opts .TitleOpts (title ="用户访问(月)",subtitle =f"月访问量: {sum(OOO0O000OOOOO00OO)} /次")))
    return OOOOO000O0000OOO0 .dump_options_with_quotes ()
